package org.android.cosmus.indiam.activities;

import org.android.cosmus.indiam.R;
import org.android.cosmus.indiam.views.CustomArrayAdapter;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.TextView;

public class MainMenuActivity extends ListActivity
{
  String[] m_menuArray;
  
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_view);
    
    m_menuArray = this.getResources().getStringArray(R.array.main_menu);
    CustomArrayAdapter adapter = new CustomArrayAdapter(this, m_menuArray);
    setListAdapter(adapter);
    
    this.getListView().setOnItemLongClickListener(new OnItemLongClickListener()
    {
      @Override
      public boolean onItemLongClick(AdapterView<?> arg0, View v, int pos, long id)
      {
        return onLongListItemClick(v,pos,id);
      }
    });
  }

  protected boolean onLongListItemClick(View v, int pos, long id)
  {
    String[] infoArray = this.getResources().getStringArray(R.array.menu_information);
    TextView listInformation = (TextView) this.getLayoutInflater().inflate(R.layout.list_text_information, null);
    listInformation.setText(infoArray[pos]);
    new AlertDialog.Builder(this).setTitle(m_menuArray[pos])
                                 .setView(listInformation)
                                 .setPositiveButton("OK", null)
                                 .show();
    return true;
  }
  
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id)
  {
    super.onListItemClick(l, v, position, id);

    switch (position)
    {
      case 0:
        startActivity(new Intent("org.android.cosmus.indiam.activities.SEARCH"));
        break;
      case 1:
        startActivity(new Intent("org.android.cosmus.indiam.activities.TUTORIAL"));
        break;
      default:
        break;
    }
  }
}
